package com.bzsg.rightsManagementSystem.service.impl

import com.bzsg.rightsManagementSystem.dao.RoleDao
import com.bzsg.rightsManagementSystem.dao.RolePermissionRelationDao
import com.bzsg.rightsManagementSystem.pojo.Role
import com.bzsg.rightsManagementSystem.service.RoleService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service


@Service
class RoleServiceImpl : RoleService {
    @Autowired
    private lateinit var roleDao: RoleDao

    @Autowired
    private lateinit var rolePermissionRelationDao: RolePermissionRelationDao
    override fun queryById(id: Int): Role? {
        return roleDao.queryById(id)
    }

    override fun queryAllByLimit(offset: Int, limit: Int): List<Role>? {
        val start = (offset - 1) * limit
        return roleDao.queryAllByLimit(start, limit)
    }

    override fun queryAll(): List<Role>? {
        return roleDao.queryAll()
    }

    override fun insert(newRole: Role) {
        roleDao.insert(newRole)
    }

    override fun update(newRole: Role) {
        roleDao.update(newRole)
    }

    override fun deleteById(id: Int) {
        roleDao.deleteById(id)
    }

    override fun selectRolesByUserId(userId: Int): List<Role>? {
        return roleDao.selectRolesByUserId(userId)
    }

    override fun selectTotalRole(): Int {
        return roleDao.selectTotalRole()
    }

    override fun addRolePermissionRelation(roleId: Int, permissionId: Int) {
        rolePermissionRelationDao.addRolePermissionRelation(roleId, permissionId)
    }

    override fun deleteAllRolePermissionRelationByRoleId(roleId: Int) {
        rolePermissionRelationDao.deleteAllRolePermissionRelationByRoleId(roleId)
    }
}